
var intervarID
const sendSms = {
    data() {
        return {
            countTime: 0,
            mobile: '',
            vcode: "",
            smsDisabled: false
        }
    },
    created() {

    },
    methods: {
        onInputTel(e) {
            this.mobile = e.detail.value
        },
        onInputVcode(e) {
            this.vcode = e.detail.value
        },
        onSendSms() {
            if (this.mobile == "") {
                uni.showToast({
                    title: "请输入手机号",
                    duration: 2000,
                    icon: "none",
                });
                return;
            }
            this.disabled = true
            this.$api.sendSms({ mobile: this.mobile }).then((res) => {
                if (res.code == 200) {
                    this.countTime = 59;
                    this.disabled = false
                    intervarID = setInterval(() => {
                        this.countTime--;
                        if (this.countTime < 0) {
                            clearInterval(intervarID);
                        }
                    }, 1000);
                    uni.showToast({
                        title: "验证码已发送",
                        duration: 2000
                    });
                }
            });
        },
    },

}
export default sendSms